package com.bst.bsj.common.dal.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.bst.bsj.common.dal.daointerface.SeedlingDAO;
import com.bst.bsj.common.dal.dataobject.Seedling;
import com.bst.bsj.common.maopu.enums.SeedlingStatus;
import com.sylinxsoft.tools.dao.impl.CommonBaseDAOImpl;

@Service("seedlingDAO")
public class SeedlingDAOImpl extends CommonBaseDAOImpl implements SeedlingDAO {

  @Override
  public Long getCounts(Map paramMap) {
    return (Long) getSqlMapClientTemplate().queryForObject(getNameSpace() + ".MS_QUERY_COUNT", paramMap);
  }

  @Override
  public List<Seedling> selectAll(Map paramMap, Long offset, Long length) {
    paramMap.put("offset", offset);
    paramMap.put("length", length);
    return (List<Seedling>) this.getSqlMapClientTemplate().queryForList(getNameSpace() + ".MS_QUERY_PAGE", paramMap);
  }

  @Override
  public Seedling getSeedling(Long id) {
    return (Seedling) getSqlMapClientTemplate().queryForObject(getNameSpace() + ".MS_SELECT", id);
  }

  @Override
  public int update(Seedling seedling) {
    return getSqlMapClientTemplate().update(getNameSpace() + ".MS_UPDATE", seedling);
  }

  @Override
  public List<Seedling> selectAllHots(Map<String, Object> paramsMap) {
    return (List<Seedling>) this.getSqlMapClientTemplate().queryForList(getNameSpace()// 
        + ".MS_HOTS_PAGE", paramsMap);
  }

  @Override
  public int updateSort(Map<String, Object> params) {
    return getSqlMapClientTemplate().update(getNameSpace() + ".MS_UPDATE_SORT", params);
  }

  @Override
  public Long getMaxSeq() {
    return (Long) getSqlMapClientTemplate().queryForObject(getNameSpace() + ".QUERY_MAX_SEQ");
  }

  @Override
  public List<Map<String, Object>> getCategory(Map<String, Object> paramsMap) {
    
    return (List<Map<String, Object>>) this.getSqlMapClientTemplate().queryForList(getNameSpace()// 
        + ".MS_CATEGORY", paramsMap);
  }

  @Override
  public List<Map<String, Object>> getSeedlingType(Map<String, Object> paramsMap) {
    return (List<Map<String, Object>>) this.getSqlMapClientTemplate().queryForList(getNameSpace()// 
        + ".MS_SEEDLINGTYPE", paramsMap);
  }

  @Override
  public List<Seedling> queryOrderById(Map<String, Object> paramMap) {
    return (List<Seedling>) this.getSqlMapClientTemplate().queryForList(getNameSpace() + ".MS_SOLD_QUERY", paramMap);
  }
  
  @Override
  public int soldTimeUpdate(List<Long> idList){
    Map<String,Object> map=new HashMap<String, Object>();
    map.put("ids", idList);
    map.put("status", SeedlingStatus.WAITSALE.getCode());
    map.put("isHot", 0);
    return this.getSqlMapClientTemplate().update(getNameSpace() + ".MS_BATCH_SOLDOUT", map);
  }

  @Override
  public Long getOnSaleCount(Map<String, Object> paramMap) {
    return (Long) getSqlMapClientTemplate().queryForObject(getNameSpace() + ".MS_ONSALE_COUNT", paramMap);
  }

  @Override
  public List<Seedling> getAfterHots(Map<String, Object> params) {
    return (List<Seedling>) this.getSqlMapClientTemplate().queryForList(getNameSpace() + ".MS_AFTER_HOTS", params);
  }

  @Override
  public void deleteByParams(Map<String, Object> paramsMap) {
    getSqlMapClientTemplate().delete(getNameSpace() + ".MS_DELETE", paramsMap);
  }

  
}
